<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2018/3/14
 * Time: 10:07
 */

namespace app\index\controller;
use think\Controller;
use think\Session;
use think\Request;
use think\View;
use think\Db;
use think\Validate;
use app\index\validate\Valid;

class Wdbf extends Common
{
    /**
     * 我的网点拜访
     * @return mixed
     */
    public function mynetbaifang(){
        $wdmc = $this->request->param('wdmc');
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $bfxl = $this->request->param('bfxl');
        $zt = $this->request->param('zt');
        $this->assign('wdmc',$wdmc);
        $this->assign('start',$start);
        $this->assign('end',$end);
        $this->assign('bfxl',$bfxl);
        $this->assign('zt',$zt);
        $where = [];
        $where['bfr'] = session('employee_id');
        if($wdmc){
            $where['wdmc'] = ['like','%'.$wdmc.'%'];
        }
        if($start&&!$end){
            $where['rq'] = ['>=',$start];
        }elseif(!$start&&$end){
            $where['rq'] = ['<=',$end];
        }elseif($start&&$end){
            $where['rq'] = [['>=',$start],['<=',$end],'and'];
        }
        if($bfxl){
            $where['bfxl'] = ['like','%'.'%'];
        }
        if($zt){
            $where['zt'] = $zt;
        }
        $cnt = db('yd_wdbf')->where($where)->count();
        $data = db('yd_wdbf')->where($where)->paginate(10,$cnt);
//        echo db('y_wdbf')->getLastSql();
        $page = $data->render();
        $data = $data->items();
        $this->assign([
            'page'=>$page,
            'data'=>$data,
        ]);
        return $this->fetch();
    }
    /**
     * 我的网点拜访报告
     * @return mixed
     */
    public function mynetbaifang1(){
        return $this->fetch();
    }
    /**
     * 我的已安排的网点拜访路线
     * @return mixed
     */
    public function mynetbaifang2(){
        return $this->fetch();
    }
    /**
     * 我的网点拜访路线管理
     * @return mixed
     */
    public function mynetbaifang3(){
        $xlbh = $this->request->param('xlbh');
        $xlmc = $this->request->param('xlmc');
        $bfwd = $this->request->param('bfwd');
        $xgry = $this->request->param('xgry');
        $sscs = $this->request->param('sscs');
        $this->assign('xlbh',$xlbh);
        $this->assign('xlmc',$xlmc);
        $this->assign('bfwd',$bfwd);
        $this->assign('xgry',$xgry);
        $this->assign('sscs',$sscs);
        $where = [];
        $where['cuser'] = session('employee_id');
        $where['isdel'] = ['<>',1];
        if($xlbh){
            $where['xlbh'] = ['like','%'.$xlbh.'%'];
        }

        if($xlmc){
            $where['xlmc'] = ['like','%'.$xlmc.'%'];
        }
        if($bfwd){
            $nets = db('cg_net')->where('title','like',"%{$bfwd}%")->column('id');
            $t = [];
            foreach($nets as $k=>$v){
                $t[] = ['like','%"'.$v.'"%'];
            }
            if($t)
                $where['bfwd'] = array_merge($t,['or']);
        }
        if($xgry){
            $nets = db('employee')->where('em_name','like',"%{$xgry}%")->column('id');
            $t = [];
            foreach($nets as $k=>$v){
                $t[] = ['like','%"'.$v.'"%'];
            }
            if($t)
                $where['xgry'] = array_merge($t,['or']);
        }
        if($sscs){
            $nets = db('cg_market_city')->where('title','like',"%{$sscs}%")->column('id');
            $t = [];
            foreach($nets as $k=>$v){
                $t[] = ['like','%"'.$v.'"%'];
            }
            if($t)
                $where['sscs'] = array_merge($t,['or']);
        }
        $cnt = db('yd_wdbfxl')->where($where)->count();
        $data = db('yd_wdbfxl')->where($where)->paginate(10,$cnt);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){
            $v['sscs'] = unserialize($v['sscs']);
            foreach($v['sscs'] as $k1=>$v1){
                $v['sscs'][$k1] = db('cg_market_city')->where('id',$v1)->value('title');
            }
            $v['sscs'] = implode(',',$v['sscs']);
            $v['bfwd'] = unserialize($v['bfwd']);
            foreach($v['bfwd'] as $k1=>$v1){
                $v['bfwd'][$k1] = db('cg_net')->where('id',$v1)->value('title');
            }
            $v['bfwd'] = implode(',',$v['bfwd']);
            $v['xgry'] = unserialize($v['xgry']);
            foreach($v['xgry'] as $k1=>$v1){
                $v['xgry'][$k1] = db('employee')->where('id',$v1)->value('em_name');
            }
            $v['xgry'] = implode(',',$v['xgry']);
            $v['cuser'] = db('employee')->where('id',$v['cuser'])->value('em_name');
            $data[$k] = $v;
        }
        $this->assign([
            'page'=>$page,
            'data'=>$data,
        ]);
        return $this->fetch();
    }
    /**
     * 我的网点拜访路线管理--回收站
     * @return mixed
     */
    public function mynetbaifang3issel(){
        $xlbh = $this->request->param('xlbh');
        $xlmc = $this->request->param('xlmc');
        $bfwd = $this->request->param('bfwd');
        $xgry = $this->request->param('xgry');
        $sscs = $this->request->param('sscs');
        $this->assign('xlbh',$xlbh);
        $this->assign('xlmc',$xlmc);
        $this->assign('bfwd',$bfwd);
        $this->assign('xgry',$xgry);
        $this->assign('sscs',$sscs);
        $where = [];
        $where['cuser'] = session('employee_id');
        $where['isdel'] = 1;
        if($xlbh){
            $where['xlbh'] = ['like','%'.$xlbh.'%'];
        }

        if($xlmc){
            $where['xlmc'] = ['like','%'.$xlmc.'%'];
        }
        if($bfwd){
            $nets = db('cg_net')->where('title','like',"%{$bfwd}%")->column('id');
            $t = [];
            foreach($nets as $k=>$v){
                $t[] = ['like','%"'.$v.'"%'];
            }
            if($t)
                $where['bfwd'] = array_merge($t,['or']);
        }
        if($xgry){
            $nets = db('employee')->where('em_name','like',"%{$xgry}%")->column('id');
            $t = [];
            foreach($nets as $k=>$v){
                $t[] = ['like','%"'.$v.'"%'];
            }
            if($t)
                $where['xgry'] = array_merge($t,['or']);
        }
        if($sscs){
            $nets = db('cg_market_city')->where('title','like',"%{$sscs}%")->column('id');
            $t = [];
            foreach($nets as $k=>$v){
                $t[] = ['like','%"'.$v.'"%'];
            }
            if($t)
                $where['sscs'] = array_merge($t,['or']);
        }
        $cnt = db('yd_wdbfxl')->where($where)->count();
        $data = db('yd_wdbfxl')->where($where)->paginate(10,$cnt);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){
            $v['sscs'] = unserialize($v['sscs']);
            foreach($v['sscs'] as $k1=>$v1){
                $v['sscs'][$k1] = db('cg_market_city')->where('id',$v1)->value('title');
            }
            $v['sscs'] = implode(',',$v['sscs']);
            $v['bfwd'] = unserialize($v['bfwd']);
            foreach($v['bfwd'] as $k1=>$v1){
                $v['bfwd'][$k1] = db('cg_net')->where('id',$v1)->value('title');
            }
            $v['bfwd'] = implode(',',$v['bfwd']);
            $v['xgry'] = unserialize($v['xgry']);
            foreach($v['xgry'] as $k1=>$v1){
                $v['xgry'][$k1] = db('employee')->where('id',$v1)->value('em_name');
            }
            $v['xgry'] = implode(',',$v['xgry']);
            $v['cuser'] = db('employee')->where('id',$v['cuser'])->value('em_name');
            $data[$k] = $v;
        }
        $this->assign([
            'page'=>$page,
            'data'=>$data,
        ]);
        return $this->fetch();
    }

    /**
     * 下属网点拜访
     * @return mixed
     */
    public function xiashunetbfa(){
        $wdmc = $this->request->param('wdmc');
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $bfxl = $this->request->param('bfxl');
        $zt = $this->request->param('zt');
        $bfr = $this->request->param('bfr');
        $this->assign('wdmc',$wdmc);
        $this->assign('start',$start);
        $this->assign('end',$end);
        $this->assign('bfxl',$bfxl);
        $this->assign('zt',$zt);
        $this->assign('bfr',$bfr);
        $where = [];
        //查询我负责的部门下属的所有人员
        $bmids = db('department t')->join('department_employee t2','t.id=t2.department_id')->where(['t.principal'=>session('emplyee_id'),'t2.index'=>1])->column('t2.employee_id');
        $where['bfr'] = ['in',$bmids];
        if($wdmc){
            $where['wdmc'] = ['like','%'.$wdmc.'%'];
        }
        if($start&&!$end){
            $where['rq'] = ['>=',$start];
        }elseif(!$start&&$end){
            $where['rq'] = ['<=',$end];
        }elseif($start&&$end){
            $where['rq'] = [['>=',$start],['<=',$end],'and'];
        }
        if($bfxl){
            $where['bfxl'] = ['like','%'.'%'];
        }
        if($zt){
            $where['zt'] = $zt;
        }
        if($bfr){
            $es = db('employee')->where('em_name','like',"%{$bfr}%")->column('id');
            $t = [];
            foreach($es as $k=>$v){
                $t[] = ['like','%"'.$v.'"%'];
            }
            if($t)
                $where['bfr'] = array_merge($t,['or']);
        }
        $cnt = db('yd_wdbf')->where($where)->count();
//        echo db('yd_wdbf')->getLastSql();
        $data = db('yd_wdbf')->where($where)->paginate(10,$cnt);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){
            $v['bm'] = db('department t')->join('department_employee t2','t2.department_id=t.id')->value('t.de_name');
            $v['bfr'] =  db('employee')->where('id',$v['bfr'])->value('em_name');
            $data[$k] = $v;
        }
        $this->assign([
            'page'=>$page,
            'data'=>$data,
        ]);
        return $this->fetch();
    }

    /**
     * 网点拜访详情
     */
    public function qiandaodetail(){
        $id = $this->request->param('id');
        $data = db('yd_wdbf')->where('id',$id)->find();
        $data['bfr'] =  db('employee')->where('id',$data['bfr'])->value('em_name');
        $data['wdfzr'] = db('cg_net')->where('id',$data['wdid'])->value('stuff');
        $data['wdfzr'] = unserialize($data['wdfzr']);
        $t = [];
        $t2 = [];
        foreach($data['wdfzr'] as $k=>$v){
            $t[] = db('employee')->where('id',$v)->value('em_name');
            $t2[] = db('employee')->where('id',$v)->value('mobile');
        }
        $data['wdfzr'] = implode(',',$t);
        $data['lxdh'] = implode(',',$t2);
        $data['detailAddress'] = db('cg_net')->where('id',$data['wdid'])->value('detailAddress');

        $this->assign('data',$data);

        return $this->fetch();
    }

    /**
     * 下属网点拜访报告
     * @return mixed
     */
    public function xiashunetbfa1(){
        return $this->fetch();
    }
    /**
     * 下属已下发的网点拜访线路
     * @return mixed
     */
    public function xiashunetbfa2(){
        return $this->fetch();
    }
    /**
     * 下属网点拜访线路管理
     * @return mixed
     */
    public function xiashunetbfa3(){
        $xlbh = $this->request->param('xlbh');
        $xlmc = $this->request->param('xlmc');
        $bfwd = $this->request->param('bfwd');
        $xgry = $this->request->param('xgry');
        $sscs = $this->request->param('sscs');
        $this->assign('xlbh',$xlbh);
        $this->assign('xlmc',$xlmc);
        $this->assign('bfwd',$bfwd);
        $this->assign('xgry',$xgry);
        $this->assign('sscs',$sscs);
        $where = [];
        //查询我负责的部门下属的所有人员
        $bmids = db('department t')->join('department_employee t2','t.id=t2.department_id')->where(['t.principal'=>session('emplyee_id'),'t2.index'=>1])->column('t2.employee_id');
        $where['cuser'] = ['in',$bmids];

        $where['isdel'] = ['<>',1];
        if($xlbh){
            $where['xlbh'] = ['like','%'.$xlbh.'%'];
        }

        if($xlmc){
            $where['xlmc'] = ['like','%'.$xlmc.'%'];
        }
        if($bfwd){
            $nets = db('cg_net')->where('title','like',"%{$bfwd}%")->column('id');
            $t = [];
            foreach($nets as $k=>$v){
                $t[] = ['like','%"'.$v.'"%'];
            }
            if($t)
                $where['bfwd'] = array_merge($t,['or']);
        }
        if($xgry){
            $nets = db('employee')->where('em_name','like',"%{$xgry}%")->column('id');
            $t = [];
            foreach($nets as $k=>$v){
                $t[] = ['like','%"'.$v.'"%'];
            }
            if($t)
                $where['xgry'] = array_merge($t,['or']);
        }
        if($sscs){
            $nets = db('cg_market_city')->where('title','like',"%{$sscs}%")->column('id');
            $t = [];
            foreach($nets as $k=>$v){
                $t[] = ['like','%"'.$v.'"%'];
            }
            if($t)
                $where['sscs'] = array_merge($t,['or']);
        }
        $cnt = db('yd_wdbfxl')->where($where)->count();
        $data = db('yd_wdbfxl')->where($where)->paginate(10,$cnt);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){
            $v['sscs'] = unserialize($v['sscs']);
            foreach($v['sscs'] as $k1=>$v1){
                $v['sscs'][$k1] = db('cg_market_city')->where('id',$v1)->value('title');
            }
            $v['sscs'] = implode(',',$v['sscs']);
            $v['bfwd'] = unserialize($v['bfwd']);
            foreach($v['bfwd'] as $k1=>$v1){
                $v['bfwd'][$k1] = db('cg_net')->where('id',$v1)->value('title');
            }
            $v['bfwd'] = implode(',',$v['bfwd']);
            $v['xgry'] = unserialize($v['xgry']);
            foreach($v['xgry'] as $k1=>$v1){
                $v['xgry'][$k1] = db('employee')->where('id',$v1)->value('em_name');
            }
            $v['xgry'] = implode(',',$v['xgry']);
            $v['cuser'] = db('employee')->where('id',$v['cuser'])->value('em_name');
            $data[$k] = $v;
        }
        $this->assign([
            'page'=>$page,
            'data'=>$data,
        ]);
        return $this->fetch();
    }
    /**
     * 所有网点拜访
     * @return mixed
     */
    public function allnetbf(){
        return $this->fetch();
    }
    /**
     * 所有网点拜访报告
     * @return mixed
     */
    public function allnetbf1(){
        return $this->fetch();
    }
    /**
     * 所有已下发的网点拜访线路
     * @return mixed
     */
    public function allnetbf2(){
        return $this->fetch();
    }
    /**
     * 所有网点拜访线路管理
     * @return mixed
     */
    public function allnetbf3(){
        return $this->fetch();
    }
    /**
     * 拜访任务改动日志
     * @return mixed
     */
    public function bftaskmodifylog(){
        return $this->fetch();
    }
    /**
     * 网点拜访动作统计报表
     * @return mixed
     */
    public function netbfactiontjb(){
        return $this->fetch();
    }
    /**
     * 添加网点拜访线路
     * @return mixed
     */
    public function addline(){
        if($_POST){
            $data = [];
            $data['xlbh'] = $this->request->post('xlbh');
            $data['xlmc'] = $this->request->post('xlmc');
            $data['sscs'] = $this->request->post('sscs/a');
            $data['bfwd'] = $this->request->post('bfwd/a');
            $data['xgry'] = $this->request->post('xgry/a');
            $data['xlbz'] = $this->request->post('xlbz');
            $validate = new Validate([
                'xlbh|线路编号'  => 'require|max:100|unique:yd_wdbfxl',
                'xlmc|线路名称'  => 'require|max:100|unique:yd_wdbfxl',
                'xlbz|线路备注'  => 'require',
                'sscs|所属城市'  => 'require',
                'bfwd'  => 'require',
                'xgry'  => 'require',
            ]);
            if (!$validate->check($data)) {
                echo  json_encode([
                    "success"=>false,
                    "msg"=>$validate->getError()
                ]);die;
            }
            $data['bfwd'] = serialize($data['bfwd']);
            $data['sscs'] = serialize($data['sscs']);
            $data['xgry'] = serialize($data['xgry']);
            $data['cuser'] = session('employee_id');
            $data['ctime'] = date('Y-m-d H:i:s');
            $bool = Db::table('yd_wdbfxl')->insert($data);
            if(false !== $bool){
                echo  json_encode([
                    "success"=>true,
                    "msg"=>"添加成功"
                ]);die;
            }else{
                echo  json_encode([
                    "success"=>false,
                    "msg"=>"添加失败"
                ]);die;
            }

        }
        return $this->fetch();
    }

    /**
     * 修改网点拜访线路
     * @return mixed
     */
    public function updateline(){
        $id = $this->request->param('id');
        if($_POST){
            $data = [];
            $data['xlbh'] = $this->request->post('xlbh');
            $data['xlmc'] = $this->request->post('xlmc');
            $data['sscs'] = $this->request->post('sscs/a');
            $data['bfwd'] = $this->request->post('bfwd/a');
            $data['xgry'] = $this->request->post('xgry/a');
            $data['xlbz'] = $this->request->post('xlbz');
            $data['id'] = $id;
            $validate = new Validate([
                'xlbh|线路编号'  => 'require|max:100|unique:yd_wdbfxl',
                'xlmc|线路名称'  => 'require|max:100|unique:yd_wdbfxl',
                'xlbz|线路备注'  => 'require',
                'sscs|所属城市'  => 'require',
                'bfwd'  => 'require',
                'xgry'  => 'require',
            ]);
            if (!$validate->check($data)) {
                echo  json_encode([
                    "success"=>false,
                    "msg"=>$validate->getError()
                ]);die;
            }
            $data['bfwd'] = serialize($data['bfwd']);
            $data['sscs'] = serialize($data['sscs']);
            $data['xgry'] = serialize($data['xgry']);
            $bool = Db::table('yd_wdbfxl')->where('id',$id)->update($data);
            if(false !== $bool){
                echo  json_encode([
                    "success"=>true,
                    "msg"=>"修改成功"
                ]);die;
            }else{
                echo  json_encode([
                    "success"=>false,
                    "msg"=>"修改失败"
                ]);die;
            }

        }
        $data = db('yd_wdbfxl')->where('id',$id)->find();
        $data['sscs'] = unserialize($data['sscs']);
        $t = [];
        foreach($data['sscs']  as $k=>$v){
            $t[] = ['id'=>$v,'title'=>db('cg_market_city')->where('id',$v)->value('title')];
        }
        $data['sscs'] = $t;
        $data['bfwd'] = unserialize($data['bfwd']);
        $t = [];
        foreach($data['bfwd']  as $k=>$v){
            $t[] = ['id'=>$v,'title'=>db('cg_net')->where('id',$v)->value('title')];
        }
        $data['bfwd'] = $t;
        $data['xgry'] = unserialize($data['xgry']);
        $t = [];
        foreach($data['xgry']  as $k=>$v){
            $t[] = ['id'=>$v,'title'=>db('employee')->where('id',$v)->value('em_name')];
        }
        $data['xgry'] = $t;
        $this->assign('data',$data);
        return $this->fetch();
    }


    /**
     * 删除
     * @throws \think\Exception
     */
    public function deleteline(){
        $id = $this->request->param('id');
        if(!$id){
            echo  json_encode([
                "success"=>false,
                "msg"=>"参数错误"
            ]);die;
        }
        $bool = Db::table('yd_wdbfxl')->where(array('id'=>$id))->update(['isdel'=>1]);
        if(false !== $bool){
            echo  json_encode([
                "success"=>true,
                "msg"=>"删除成功"
            ]);die;
        }else{
            echo  json_encode([
                "success"=>false,
                "msg"=>"删除失败"
            ]);die;
        }
    }

    /**
     * 启用
     * @throws \think\Exception
     */
    public function qiyongline(){
        $id = $this->request->param('id');
        if(!$id){
            echo  json_encode([
                "success"=>false,
                "msg"=>"参数错误"
            ]);die;
        }
        $bool = Db::table('yd_wdbfxl')->where(array('id'=>$id))->update(['isdel'=>0]);
        if(false !== $bool){
            echo  json_encode([
                "success"=>true,
                "msg"=>"启用成功"
            ]);die;
        }else{
            echo  json_encode([
                "success"=>false,
                "msg"=>"启用失败"
            ]);die;
        }
    }

    /**
     * 下发网点拜访任务
     */
    public function xiafanettask(){
        if($_POST){
            $bfry = $this->request->post('bfry');
            $li = $this->request->post('li/a');
            $ins = [];
            foreach($li as $k=>$v){
                $t = $v['net'];
                $t = explode(',',$t);
                foreach ($t as $kk=>$vv){
                    $t2 = [];
                    $t2['bfr'] = $bfry;
                    $t2['rq'] = $v['bfrq'];
                    $t2['bfxl'] = $v['bfxl'];
                    $t2['wdid'] = $vv;
                    $t2['wdmc'] = db('cg_net')->where('id',$vv)->value('title');
                    $t2['rwdzr'] = session('employee_id');
                    $t2['rwdzr_name'] = db('employee')->where('id',session('employee_id'))->value('em_name');
                    $t2['dzsj'] = date('Y-m-d H:i:s');

                    $ins[] = $t2;
                }
            }
            $bool = db('yd_wdbf')->insertAll($ins);
            if(false!==$bool){
                echo json_encode(['success'=>true,'msg'=>'ok']);
            }else{
                echo json_encode(['success'=>false,'msg'=>'error']);
            }
            die;
        }
        return $this->fetch();
    }

    /**
     * 负责的拜访线路
     */
    public function fzdbfxl(){
        $id = $this->request->param('id');
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $em_name = db('employee')->where('id',$id)->value('em_name');
        $bfxl = db('yd_wdbfxl')->where('xgry','like','%"'.$id.'"%')->column('xlmc');
        $bfxl = implode(',',$bfxl);
        $data1 = $em_name.'负责的拜访线路有：'.$bfxl.'&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.url('mynetbaifang3').'">给'.$em_name.'设置更多拜访线路</a>';
        $start = strtotime($start);
        $end = strtotime($end);
        $data2 = '';
        $weekarray=array("日","一","二","三","四","五","六"); //先定义一个数组
        for($i=$start;$i<=$end;$i+=(24*60*60)){
            $data2 .= '<tr>
            <td>
                '.$em_name.'，星期'.$weekarray[date('w',$i)].'<br>
                '.date('Y-m-d',$i).'<input type="hidden" name="bfrq" value="'.date('Y-m-d',$i).'">
            </td>
            <td>
                <div class="form-group" class="bfxl_input">
                    <div class="input-group">
                        <input type="text" placeholder="请输入关键字或空格查询"
                               class="bfxl form-control" value="" style="min-width: 300px;width: 300px">
                        <div class="input-group-btn">
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="selectedOnlyOne" style="display: none;">
                    <input type="hidden" name="bfxl" >
                    <span class="inin"></span>
                    <span class="close">×</span>
                </div>
            </td>
            <td>

            </td>
        </tr>';
        }

        echo json_encode(['data1'=>$data1,'data2'=>$data2]);
    }

    //网点线路
    public function bswdxl(){
        $id = $this->request->param('id');

        $data = db('yd_wdbfxl')->where('xgry','like','%"'.$id.'"%')->field('id,xlmc title')->select();
        echo json_encode(['message'=>'ok','value'=>$data,'code'=>'200','redirect'=>'']);
    }

    //根据线路查网点
    public function gjxlcwd(){
        $id = $this->request->param('id');

        $data = db('yd_wdbfxl')->where('id',$id)->value('bfwd');
        $data = unserialize($data);
        $str = '';
        foreach($data as $k=>$v){
            $title = db('cg_net')->where('id',$v)->value('title');
            $str .= '<span class="ren" data-id="'.$v.'">'.$title.'<input type="hidden" name="net" value="'.$v.'"><span class="close">×</span></span>';
        }
        echo $str;
    }
    //根据线路查网点
    public function bsnetbyxl(){
        $id = $this->request->param('id');
        $data = db('yd_wdbfxl')->where('id',$id)->value('bfwd');
        $data =  unserialize($data);
        foreach ($data as $k=>$v){
            $id = $v;
            $v = [];
            $v['id'] = $id;
            $v['title'] = db('cg_net')->where('id',$id)->value('title');
            $data[$k] = $v;
        }
        echo json_encode(['message'=>'ok','value'=>$data,'code'=>'200','redirect'=>'']);
    }

    //网点
    public function net(){
        return $this->fetch();
    }


    //返回网点树数据-从分区开始
    public function netTreeAjax(){

        $id = $this->request->param('id');
        $data = db('yd_wdbfxl')->where('id',$id)->value('bfwd');
        $data =  unserialize($data);
        foreach ($data as $k=>$v){
            $id = $v;
            $v = [];
            $v['id'] = $id;
            $v['name'] = db('cg_net')->where('id',$id)->value('title');
            $data[$k] = $v;
        }
        echo json_encode($data);
    }


}